package com.test.byteDance;

import java.util.*;

class Byte2019_4 {
    public int consecutiveFrames(int[][] frames) {
        HashMap<String, List<Integer>> map = new HashMap<>();
        for (int i = 0; i < frames.length; i++) {
            int tmp = frames[i][0];
            int k = 1;
            for (int j = 0; j < tmp; j++) {
                String str = "" + frames[i][k++] +"&"+ frames[i][k++];
                List<Integer> orDefault = map.getOrDefault(str, new ArrayList<>());
                orDefault.add(i);
                map.put(str, orDefault);
            }
        }
        int max = Integer.MIN_VALUE;
        for (List<Integer> value : map.values()) {
            max = Math.max(max, continuousFeature(value));
        }
        return max;
    }

    // 最长连续帧
    public int continuousFeature(List<Integer> list) {
        list.sort(Comparator.comparingInt(o -> o));
        int max = 0;
        int tmp = 1;
        for (int i = 1; i < list.size(); i++) {
            boolean flag = false;
            while (i < list.size() && list.get(i) == list.get(i - 1) + 1) {
                flag = true;
                tmp++;
                i++;
            }
            max = Math.max(max, tmp);
            tmp = 1;
            if (flag) {
                i--;
            }
        }
        return max;
    }
}

class Main {
    public static void main(String[] args) {
        Byte2019_4 byte2019_4 = new Byte2019_4();
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] res = new int[N];

        for (int k = 0; k < N; k++) {
            int M = scanner.nextInt();
            int[][] frames = new int[M][10000];
            for (int i = 0; i < M; i++) {
                frames[i][0] = scanner.nextInt();
                for (int j = 1; j <= (frames[i][0] * 2); j++) {
                    frames[i][j] = scanner.nextInt();
                }
            }
            res[k] = byte2019_4.consecutiveFrames(frames);
        }
        for (int re : res) {
            System.out.println(re);
        }
        /*List<Integer> list = Arrays.asList(1, 3, 5, 7, 9);
        System.out.println(byte2019_4.continuousFeature(list));*/
    }
}
